
//-------------------------------------------
const int ledPin = 13;       // the pin that the LED is attached to

const byte NUM_JOYSTICKS = 3;
const byte NUM_PINS = 4;
const int joystickPin[NUM_JOYSTICKS][NUM_PINS] = { 
  { 22, 24, 26, 28   } ,
  { 32, 30, 36, 34   } ,
  { 40, 38, 44, 42   } 
};

int joystickState[NUM_JOYSTICKS][NUM_PINS];
int joystickLastState[NUM_JOYSTICKS][NUM_PINS];

//-------------------------------------------
void setup() {

  //--led
  pinMode(ledPin, OUTPUT);

  //--pins
  for(int i = 0; i < NUM_JOYSTICKS; i++) {
    for(int p = 0; p < NUM_PINS; p++) {
      pinMode( joystickPin[i][p], INPUT);
      joystickState[i][p] = LOW;
      joystickLastState[i][p] = LOW;
    }
  } 
  
  //--serial
  Serial.begin(9600);
  Serial.println("-arduino");  //passing 8 bytes '-arduino' to confirm connection to oF
}

//-------------------------------------------
void loop() {

  for(int i = 0; i < NUM_JOYSTICKS; i++) {

    for(int p = 0; p < NUM_PINS; p++) {
           
      joystickState[i][p] = digitalRead( joystickPin[i][p] );

      if (joystickState[i][p] != joystickLastState[i][p] ) {

        if (joystickState[i][p] == HIGH) {
          Serial.print("j");
          Serial.print(i);
          Serial.print(".");
          Serial.print("p");
          Serial.print(p);
          Serial.print(".");
          Serial.print("s");
          Serial.println("1");
        }
        else if (joystickState[i][p] == LOW) {
          Serial.print("j");
          Serial.print(i);
          Serial.print(".");
          Serial.print("p");
          Serial.print(p);
          Serial.print(".");
          Serial.print("s");
          Serial.println("0");
        }
        else {
          Serial.print("---joystickState[i][p] neither HIGH or LOW");
        }

        joystickLastState[i][p] = joystickState[i][p];
        
      }   //STATE
    }     //NUM_PINS
  }       //NUM_JOYSTICKS
}










